home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Paypal_En / Configuration / Commands / Edit PayPal View Cart.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  9.0 KB  |  226 lines

  1. /*-----------------------------------------------------------------------------
  2. -    File Name:
  3. -        Edit PayPal View Cart.js
  4. -
  5. -    Description:
  6. -        Functions for PayPal View Cart Advanced Mode.
  7. -
  8. -    This file contains proprietary and confidential information from WebAssist.com
  9. -    corporation.  Any unauthorized reuse, reproduction, or modification without
  10. -    the prior written consent of WebAssist.com is strictly prohibited.
  11. -
  12. -    Copyright 2001 WebAssist.com Corporation.  All rights reserved.
  13. ------------------------------------------------------------------------------*/
  14. var CURRENTPAGE = 0;
  15. var theTag = "";
  16. var INSPECTIONPARAMS = false;
  17. var INTERFACE        = "advanced";
  18. var theOrig = "";
  19. var updateVersion = false;
  20.  
  21. function displayHelp()     {
  22.   INTERFACE   = "advanced";
  23.   displayContextHelp();
  24. }
  25.  
  26. function receiveArguments()     {
  27.   INSPECTIONPARAMS = true;
  28. }
  29.  
  30. /*************************** end tab definitions ***************************/
  31. /* Initialize the UI.  First thing that's called on the body load event. */
  32. function initializeUI()     {
  33.   MM.setBusyCursor();  
  34.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  35.     document.cancel.style = "position:absolute; width:70px; height:20px; z-index:94; left: 310px; top: 355px; visibility: visible";
  36.     document.cancel.document.btnCancel.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  37.     
  38.     document.OK.style = "position:absolute; width:70px; height:20px; z-index:94; left: 380px; top: 355px; visibility: visible";
  39.     document.OK.document.btnOK.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  40.     
  41.     document.help.style = "position:absolute; width:70px; height:20px; z-index:94; left: 240px; top: 355px; visibility: visible";
  42.     document.help.document.btnHelp.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  43.   
  44.     document.walogo.top = 360;
  45.     document.pplogo.top = 361;
  46.     }
  47.   document.OK.visibility = "visible";
  48.   document.cancel.visibility = "visible";
  49.   document.help.visibility = "visible";
  50.   // Get values from the inspected node and populate our UI accordingly
  51.   var theDOM = dw.getDocumentDOM();
  52.   var theSelection = theDOM.getSelectedNode();
  53.   theOrig = unescape(theSelection.orig);
  54.   if (getTagType(theOrig).toLowerCase() == "a")  {
  55.     updateVersion = true;
  56.     var theImg = theOrig.match(/<img\s.*src=(['"])([^'"]*)\1/)[2];
  57.     theOrig = theOrig.match(/(['"])[^'"]*https?:\/\/www\.paypal\.com\/cart\/([^'"]*)\1/i)[2];
  58.     theOrig = "cmd=_cart&"+theOrig;
  59.     theOrig = '<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="image" name="submit" src="'+theImg+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">\r\n<input type="hidden" name="' + theOrig.replace(/=/g,'" value="').replace(/\&/g,'">\r\n<input type="hidden" name="') + '">\r\n</form>';
  60.   }
  61.   else  {
  62.     while (theSelection.tagName!="FORM" && theSelection.parentNode && theSelection.PPwholeForm!="true")  {
  63.       theSelection = theSelection.parentNode;
  64.     }
  65.     theOrig = theSelection.outerHTML;
  66.   }
  67.   var tempOrig = theOrig;
  68.   var firstInput = findOpenTag(tempOrig,"input");
  69.   while (firstInput != "")
  70.   {
  71.     var inputName = getTagProp(firstInput,"input","name");
  72.     var theVal = getTagProp(firstInput,"input","value");
  73.     switch (inputName.toLowerCase())
  74.     {
  75.       case "business":
  76.         if (theVal != "")   
  77.           document.generalWP.document.ppUID.value = theVal;      
  78.         break;
  79.  
  80.       case "submit":  // button image URL
  81.         var theImg = document.generalWP.document.vcimage;   
  82.         theVal = getTagProp(firstInput,"input","src");
  83.         var myImage = getTranslatedVCImage(theVal);
  84.         if (myImage == CUSTOM_VC_IMG)
  85.         {
  86.           myImage = "other";
  87.           document.generalWP.document.othervcimage.value = theVal;
  88.         }
  89.         
  90.         for (var n=0; n<theImg.length; n++)
  91.         {
  92.             if (myImage == theImg[n].value)
  93.             {
  94.               theImg[n].checked = true;
  95.             }
  96.             else
  97.             {
  98.               theImg[n].checked = false;
  99.             }
  100.         }              
  101.         break;                                                                                
  102.                         
  103.       default:
  104.         break;
  105.     }   
  106.     tempOrig = tempOrig.substring(tempOrig.indexOf(firstInput)+firstInput.length); 
  107.     firstInput = findOpenTag(tempOrig,"input");
  108.     
  109.   }  
  110.   enableDisableOtherImage('VC');
  111.   
  112.   Pg0_Load()
  113.   
  114.   MM.clearBusyCursor();
  115.   
  116.   return true;
  117. }
  118.  
  119. function insertTag()    {
  120.   var myErrors = validateUI();
  121.   if (myErrors == "")
  122.   {
  123.     updateVC(theOrig);
  124.   }
  125.   else
  126.   {
  127.     alert (myErrors);
  128.   }
  129. }
  130.  
  131.  
  132.  
  133. function validateUI()    {
  134.   var errMsg = "";
  135.   errMsg += validatePPUID();
  136.   if (errMsg != "")
  137.   {
  138.     errMsg = "The following errors were found:\n\n" + "Account " + errMsg;
  139.   }
  140.   return errMsg;
  141. }
  142.  
  143. function updateVC(formTag)  {
  144.   var theForm = formTag;
  145.   var theBusiness = document.generalWP.document.ppUID.value;
  146.   var theButtonImage = document.generalWP.document.vcimage[0].value;
  147.   for (x in document.generalWP.document.vcimage)  {
  148.     if (document.generalWP.document.vcimage[x].checked)
  149.       theButtonImage = document.generalWP.document.vcimage[x].value;
  150.   }
  151.   if (theButtonImage == "other")
  152.     theButtonImage = document.generalWP.document.othervcimage.value;
  153.   else  
  154.     theButtonImage = "http://images.paypal.com/images/" + theButtonImage;
  155.   theForm = updateFormInput(theForm,"business",theBusiness);
  156.   theForm = updateFormInput(theForm,"bn",BNVersion);
  157.   theForm = updateImage(theForm,theButtonImage);
  158.   var theDOM = dreamweaver.getDocumentDOM();
  159.   var thePage = theDOM.documentElement.outerHTML;
  160.   var theSelection = theDOM.getSelectedNode();
  161.   var theOffsets = new Array();
  162.   if (!updateVersion)  {
  163.     while (theSelection.tagName!="FORM" && theSelection.PPwholeForm!="true")  {
  164.       theSelection = theSelection.parentNode;
  165.     }
  166.   }
  167.   theDOM.setSelectedNode(theSelection);
  168.   theDOM.insertHTML(theForm);
  169.   closeWindow();
  170. }
  171.  
  172. function updateImage(formHTML,image)  {
  173.   var theInput = /<input\s[^<]*type=(['"])image\1/i;
  174.   if (formHTML.search(theInput)>=0)  {
  175.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  176.     formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","src",image) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  177.   }
  178.   else  {
  179.     formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="image" name="submit" src="'+image+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  180.   }
  181.   return formHTML;
  182. }
  183.  
  184. function updateFormInput(formHTML,fieldName,fieldValue)  {
  185.   var theInput = new RegExp('<input\\s[^<]*name=([\'"]?)'+fieldName+'\\1',"i");
  186.   if (formHTML.search(theInput)>=0)  {
  187.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  188.     if (fieldValue!="")
  189.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","value",fieldValue) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  190.     else
  191.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  192.   }
  193.   else  {
  194.     if (fieldValue!="")
  195.       formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="hidden" name="'+fieldName+'" value="'+fieldValue+'">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  196.   }
  197.   return formHTML;
  198. }
  199.  
  200. /******************************** PAGE FUNCTIONS ********************************/
  201. function Pg0_Load()     {
  202.   document.generalWP.document.ppUID.focus();
  203.   return true;
  204. }
  205. function Pg0_unLoad()     {
  206.   return true;
  207. }
  208.  
  209. function showPageNum(pageNum)  {
  210.   eval("Pg"+CURRENTPAGE+"_unLoad()");
  211.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  212.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg_Mac.gif'");
  213.   }
  214.   else  {
  215.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg.gif'");
  216.   }
  217.   CURRENTPAGE = pageNum;
  218.    if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  219.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel_Mac.gif'");
  220.    }
  221.   else  {  
  222.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel.gif'");
  223.   }
  224.   eval("Pg"+CURRENTPAGE+"_Load()");
  225. }
  226.